package com.hfjc.handle;


import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hfjc.entity.ResultBack;
import com.hfjc.exception.ProductException;
import com.hfjc.util.ResultBackUtil;

@ControllerAdvice
public class ExceptionHandle {

	
	
	@ExceptionHandler(value=Exception.class)
	@ResponseBody
	public ResultBack handle(Exception e){
		if(e instanceof ProductException){
			ProductException p = (ProductException) e;
			return ResultBackUtil.error(p.getCode(),p.getMessage());
		}
		else{
			return ResultBackUtil.error(-1,"未知错误");
		}
	
	}
}
